<template>
	<view>
		<uamhead :title="title"></uamhead>
		<view class="search">
			<uni-search-bar @confirm="search" :focus="true" cancelButton="none" v-model="searchValue" @blur="blur"
				@focus="focus" @input="input" @cancel="cancel" @clear="clear">
			</uni-search-bar>
			<view v-if="searchValue.length === 0" class="hot">
				<text class="hotname">热搜榜</text>
				<view v-for="(item, index) in playlist" :key="index" class="list-item">
					<uni-list-item class="list-item-content">
						<view class="item-container">
							<view class="index-container">
								<text :class="{'xuhao-red': index <= 2, 'xuhao-gray': index > 2}"
									class="xuhao">{{ index + 1 }}</text>
							</view>
							<text class="name">{{ item.searchWord }}</text>
						</view>
					</uni-list-item>
				</view>
			</view>
			<view v-else>
				<text class="search-result-text">搜索：{{ searchValue }}</text>
				<view v-for="(item, index) in searchlist" :key="index" class="SongBox">
					<text class="SongName" @click="navPlayer(item.id)">{{item.name}}</text><br>
					<text class="Songzj">{{item.ar[0].name}}--{{item.al.name}}</text>
				</view>
			</view>
		</view>
	</view>
</template>


<script>
	import {
		SearchHot,
		Search
	} from '../../common/api.js';

	export default {
		data() {
			return {
				title: '搜索',
				searchValue: '',
				playlist: [],
				searchlist: [],
			}
		},
		onLoad() {
			SearchHot().then((res) => {
				this.playlist = res.data.data;
			});
		},
		methods: {
			search() { //搜索功能
				Search(this.searchValue).then((res) => {
					this.searchlist = res.data.result.songs;
				}).catch((error) => {
					console.error('搜索出错：', error);
				});
			},
			navPlayer(id) {
				console.log(id);
				uni.navigateTo({
					url: '/pages/player/player?songid=' + id,
				})
			}
		}
	}
</script>



<style scoped>
	.search {
		padding-top: 50rpx;
	}

	.hotname {
		font-size: 30rpx;
	}

	.xuhao-red {
		color: red;
		text-align: center;
		padding-left: 10rpx;
	}

	.xuhao-gray {
		color: gray;
		text-align: center;
		padding-left: 10rpx;
	}

	.name {
		padding-left: 50rpx;

	}

	.index-container {
		width: 30rpx;
		margin-right: 10rpx;
	}

	.item-container {
		display: flex;
		align-items: center;
	}

	.playlist-container {
		background-color: #f5f5f5;
	}

	.bangming {
		width: 750rpx;
		height: 450rpx;
		background-color: pink;

	}

	.tupian img {
		width: 250rpx;
		height: 250rpx;
		border-radius: 10%;
		margin: 90rpx 0 0 20rpx;
	}

	.list-item {
		border-bottom: 1px solid #e5e5e5;
		padding: 10px 0;
	}

	.list-item-content {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.list-item-details {
		flex: 1;
		display: flex;
		flex-direction: column;
	}

	.song-info {
		display: flex;
		align-items: center;
	}

	.list-index {
		color: #999;
		margin-right: 10px;
		margin-bottom: 100rpx;
	}

	.list-song-name {
		font-size: 18px;
		color: #333;
		margin-bottom: 5px;
	}

	.list-artist-album {
		font-size: 14px;
		color: #666;
		margin-bottom: 30px;
	}

	.zuozhe {
		display: flex;
	}

	.tp {
		width: 30rpx;
		height: 20rpx;
		margin-top: 10rpx;
	}

	.show-image {
		display: block;
	}

	.hide-image {
		display: none;
	}

	.SongBox {
		margin-bottom: 30rpx;
	}

	.Songzj {
		font-size: 20rpx;
		color: #999;
	}

	.search-result-text {
		font-size: 30rpx;
	}
</style>